   package com.javalong.affairs.module.userModule.fragment;

import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.google.gson.reflect.TypeToken;
import com.javalong.affairs.R;
import com.javalong.affairs.base.constant.RequestKey;
import com.javalong.affairs.base.fragment.BaseFragment;
import com.javalong.affairs.base.listener.BaseResponseListener;
import com.javalong.affairs.base.model.User;
import com.javalong.affairs.base.ui.TopTitle;
import com.javalong.affairs.base.utils.HttpUtils;
import com.javalong.affairs.base.utils.ToastUtils;
import com.javalong.affairs.base.utils.UrlUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class UpdatePwdFragment extends BaseFragment implements OnClickListener {
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.et_oldpwd)
	private EditText et_oldpwd;
	@ViewInject(R.id.et_newpwd)
	private EditText et_newpwd;
	@ViewInject(R.id.bt_update)
	private Button bt_update;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_updatepwd, container,
				false);
		return view;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		ViewUtils.inject(this);
		bt_update.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_update:
			String url = UrlUtils.getUrl("User", "updatePassword");
			Map<String, Object> params = new HashMap<String, Object>();
			params.put(RequestKey.PASSWORDOLD, et_oldpwd.getText().toString());
			params.put(RequestKey.PASSWORD, et_newpwd.getText().toString());
			HttpUtils.post(url, params, new BaseResponseListener(
					new TypeToken<User>() {
					}.getType()) {
				@Override
				public void onSuccess(Object obj) {
					super.onSuccess(obj);
					ToastUtils.showMessage("密码修改成功！");
					et_oldpwd.setText("");
					et_newpwd.setText("");
				}
			});
			break;
		default:
			break;
		}
	}
}
